class User {
  static users: User[] = [];
  constructor(
    public loginId: string,
    public loginPwd: string,
    public name: string,
    public age: number
  ) {
    User.users.push(this);
  }

  sayHello() {
    console.log(
      `大家好，我叫${this.name}, 我的年龄${this.age}, 我的账号${this.loginId}`
    );
  }

  static login(loginId: string, loginPwd: string): User | undefined {
    console.log(this, "静态方法中类"); // 静态方法中的this表示当前类
    return User.users.find(
      (u) => u.loginId === loginId && u.loginPwd === loginPwd
    );
  }
}

const u1 = new User("u1", "123", "王富贵", 11);
const u2 = new User("u2", "123", "坤哥", 18);
const u3 = new User("u3", "123", "张三", 19);
console.log(User.users);
const result = User.login("u1", "123");
if (result) {
  result.sayHello();
}

export {};
